<template>
    <div class="bigData">
        <header>
            <div class="title f fac fpc">重庆农产品大数据看板</div>
            <div class="icon f fac">
                <img src="../../assets/dataImg/data_fangda.png" alt="">
                <img @click="$router.push(data.indexPath)" src="../../assets/dataImg/data_shouye.png" alt="">
            </div>
        </header>
        <main class="f fac fpa">
            <div class="left f fv fpa f1">
                <div class="item">
                    <div class="item-box">
                        <div class="title f fac">产量排名</div>
                        <div class="chart"></div>
                    </div>
                </div>
                <div class="item">
                    <div class="item-box">
                        <div class="title f fac">农作物产量趋势</div>
                        <div class="chart" v-if="Object.keys(data.chartLineData).length > 0">
                            <LineChart :legend="data.chartLineData.legend" :xAxisData="data.chartLineData.nf"
                                :seriesData1="data.chartLineData.cl" :seriesData2="data.chartLineData.mj" />
                        </div>
                    </div>
                </div>
                <div class="item">
                    <div class="item-box">
                        <div class="title f fac">农产品进出口金额</div>
                        <div class="chart" v-if="Object.keys(data.chartBarData).length > 0">
                            <BarChart :legend="data.chartBarData.legend" :xAxisData="data.chartBarData.yf"
                                :seriesData1="data.chartBarData.ck" :seriesData2="data.chartBarData.jk" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="center f fv fpa f1">
                
            </div>
            <div class="right f fv fpa f1">
                <div class="item">
                    <div class="item-box">
                        <div class="title f fac">进出口主要地区</div>
                        <div class="chart" v-if="data.chartRingData.pieData">
                            <RingChart :trafficWay="data.chartRingData.pieData" :title="data.areaType == 1 ? '进口' : '出口'" />
                            <div class="select">
                                <el-select v-model="data.areaType" @change="getChartRing()">
                                    <el-option label="进口" :value="1" />
                                    <el-option label="出口" :value="2" />
                                </el-select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="item">
                    <div class="item-box">
                        <div class="item-box">
                            <div class="title f fac">进出口金额分布</div>
                            <div class="chart c1" v-if="data.chartRadarData.pieData">
                                <!-- <RadarChart :trafficWay="data.chartRadarData.pieData" :title="data.moneyType == 1 ? '进口' : '出口'" /> -->
                                <div class="select">
                                    <el-select v-model="data.moneyType" @change="getChartRadar()">
                                        <el-option label="进口" :value="1" />
                                        <el-option label="出口" :value="2" />
                                    </el-select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="item">
                    <div class="item-box">
                        <div class="title f fac">数据共享</div>
                        <div class="chart"></div>
                    </div>
                </div>
            </div>
        </main>
    </div>
</template>

<script setup>
import { reactive, onMounted } from 'vue'
import http from '@/api/bigData'
import LineChart from '@/components/LineChart.vue'
import BarChart from '@/components/BarChart.vue'
import RingChart from '@/components/RingChart.vue'
import RadarChart from '@/components/RadarChart.vue'


// 数据对象
const data = reactive({
    indexPath: sessionStorage.getItem('indexPath'),
    // 农作物产量趋势
    chartLineData: {},
    // 农产品进出口金额
    chartBarData: {},
    // 农产品进出口分布主要地区
    chartRingData: {},
    // 农产品进出口分布金额
    chartRadarData: {},
    // 选择的进出口类别（地区）
    areaType: 1,
    // 选择的进出口类别（金额）
    moneyType: 1
})


// 获取农作物产量趋势
const getChartLine = () => {
    http.getLine().then(res => {
        data.chartLineData = res.data
    })
}

// 获取农产品进出口金额
const getChartBar = () => {
    http.getBar().then(res => {
        data.chartBarData = res.data
    })
}

// 获取农产品进出口分布地区
const getChartRing = () => {
    http.getRing({ type: data.areaType }).then(res => {
        data.chartRingData = res.data
    })
}

// 获取农产品进出口分布金额
const getChartRadar = () => {
    http.getRing({ type: data.moneyType }).then(res => {
        data.chartRadarData = res.data
    })
}


onMounted(() => {
    getChartLine()
    getChartBar()
    getChartRing()
    getChartRadar()
})


</script>

<style lang="scss" scoped>
.bigData {
    width: 100%;
    height: 100vh;
    overflow: hidden;
    // background: url("@/assets/dataImg/data_bj.jpeg") no-repeat center center;
    background: url("@/assets/dataImg/bg.jpg") no-repeat center center;
    background-size: cover;
    color: #fff;

    header {
        width: 100%;
        height: 0.9rem;
        background: url("@/assets/dataImg/data_title.png") no-repeat center center;
        background-size: cover;
        color: $ncpColor;
        font-size: 0.48rem;
        position: relative;

        .title {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
        }

        .icon {
            position: absolute;
            top: 0;
            right: 0;
            width: 1rem;
            height: 0.6rem;

            img {
                width: 0.24rem;
                height: 0.24rem;
                margin-left: 0.2rem;
                cursor: pointer;
            }
        }
    }

    main {
        width: 100%;
        height: calc(100% - 0.9rem);
        overflow: hidden;

        .left {
            margin-left: 0.2rem;
            height: 100%;
            padding-bottom: 0.1rem;
        }

        .center {
            margin: 0 0.2rem;
            height: 100%;
            padding-bottom: 0.1rem;
        }

        .right {
            margin-right: 0.2rem;
            height: 100%;
            padding-bottom: 0.1rem;
        }

        .item {
            width: 100%;
            height: calc(33% - 0.1rem);
            background: rgba(24, 38, 43, .7);
            border: 1px solid rgba(44, 94, 111, .7);
            position: relative;

            .item-box {
                width: 100%;
                height: calc(100% - 0.1rem);
                position: relative;

                // height: calc(100% - 0.3rem);
                .title {
                    margin-top: 0.1rem;
                    margin-left: 0.1rem;
                    height: 0.3rem;
                    width: 80%;
                    background: linear-gradient(90deg, #176860, #162f2f);
                    color: #d4feff;
                    font-size: 0.16rem;
                    font-weight: 700;
                    padding-left: 0.16rem;
                    border-left: 0.02rem solid #3cb1a5;
                }

                .chart {
                    width: 100%;
                    height: calc(100% - 0.3rem);
                }
                .select {
                    position: absolute;
                    right: 0.24rem;
                    top: 0.5rem;
                    width: 1.6rem;
                }
            }

        }
    }
}
</style>